//
//  UITabBarButton+Extension.swift
//  微博
//
//  Created by 吕东星 on 17/3/29.
//  Copyright © 2017年 lddongxing. All rights reserved.
//

import UIKit

//便利构造函数
extension UIBarButtonItem {
    convenience init(title : String,imageName:String? = nil ,target : Any?,action :Selector) {
       self.init()
        
        // 设置button
        let button = UIButton()
        
        if let imaName = imageName  {
            button.setImage(UIImage(named:imaName), for: .normal)
        }
        //添加点击事件
        button.addTarget(target ,action: action, for: .touchUpInside)
        
        // 设置文字
        button.setTitle(title, for: .normal)
        //设置状态
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //设置大小
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        //适应图框
        button.sizeToFit()
        
        //关联属性
       self.customView = button
        
        
        
    }

}
